﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Data
{
    using SharpSoft.Data.Expressions;
    using SharpSoft.Data.GSQL;
    public class SqliteTextGenerator : SQLTextGenerator
    {
        public override string SafetiyStartChar => "[";
        public override string SafetiyEndChar => "]";

        public override string LastAutoId =>"LAST_INSERT_ROWID()";

        public override string GetNow => "(datetime('now', 'localtime'))";
         

        protected override string ProcessColumnDefine(ColumnDefine columnDefine)
        {
            columnDefine.Comment = null;//SQLITE不支持列备注
            return base.ProcessColumnDefine(columnDefine);
        }

        protected override string ColumnAutoincrement()
        {
            return "AUTOINCREMENT";
        }

        protected override string ProcessDataType(DataType dataType)
        {
            if (dataType == DataType.Int || dataType == DataType.Long)
            {
                return "INTEGER";
            }
            return base.ProcessDataType(dataType);
        }

        protected override string ProcessExpression(BooleanExpression BO)
        {
            return BO.Content ? "1" : "0";
        }
         
        protected override NativeSQLCommandScript ProcessStatement(CreateTableStatement statement)
        {
            return base.ProcessStatement(statement);
        }

        protected override string ProcessConstraintDefine(ConstraintDefine constraintDefine)
        {
            throw new Exception("SQLITE不支持复杂的约束.");
            //return "";
        }
    }
}
